<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Post extends CI_Controller
{
	function __construct()
	{
		parent::__construct();
		$this->load->database();//加载数据库;
		$this->load->model('Post_model');
		$this->load->model('PostContent_model');
		$this->load->helper('url');
		$this->load->model('Category_model');
	}

	public function lists()
	{
		$this->load->library('pagination'); // 导入翻页类

		$config = array(
			'base_url' => '/bm/post/main', // 分页url
			'total_rows' => $this->db->count_all('post'), // 统计总数
			'per_page' => 25, // 每页显示的文件
			'use_page_numbers' => true,
			'first_link' => '首页',
			'last_link' => '末页',
			'num_links' => 5,
			'cur_tag_open' =>'<a data-ci-pagination-page>',
			'cur_tag_close' =>'</a>',
			'num_links' => 2
		);

		$data = array(
			'list' => $this->Post_model->lists($config['per_page'], $this->uri->segment(4)),
		);
		$this->pagination->initialize($config);

		$this->load->view('default/post/lists', $data);
	}

	public function detail()
	{
		$id = $this->input->get('id') ?? $this->uri->segment(4);
		$info = $this->Post_model->info($id);
		$data = array(
			'info' => $info,
		);
		$this->load->view('default/post/detail', $data);
	}
}
